
<template>
  <div class="nested-parameter-group">
    <div class="group-header">
      <h3>{{ group.groupName }}</h3>
      <div class="group-info">
        <el-tag size="mini" type="warning">嵌套参数组</el-tag>
        <span class="child-count">{{ group.childGroups.length }} 个子组</span>
      </div>
    </div>
    
    <div class="child-groups-container">
      <div
        v-for="childGroup in sortedChildGroups"
        :key="childGroup.groupId"
        class="child-group"
      >
        <div class="child-group-header">
          <h4>{{ childGroup.groupName }}</h4>
        </div>
        <div class="child-parameters">
          <parameter-field
            v-for="param in sortedChildParams(childGroup)"
            :key="param.paramId"
            :param="param"
            :value="formData[param.paramCode]"
            @change="handleFieldChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import ParameterField from './ParameterField.vue'

export default {
  name: 'NestedParameterGroup',
  components: {
    ParameterField
  },
  props: {
    group: {
      type: Object,
      required: true
    },
    formData: {
      type: Object,
      required: true
    }
  },
  computed: {
    sortedChildGroups() {
      return this.group.childGroups || []
    }
  },
  methods: {
    sortedChildParams(childGroup) {
      return [...childGroup.paramItems].sort((a, b) => a.sortOrder - b.sortOrder)
    },
    handleFieldChange({ paramCode, value }) {
      this.$emit('param-change', { paramCode, value })
    }
  }
}
</script>

<style scoped>
.nested-parameter-group {
  padding: 20px 30px;
  background: white;
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e6e8eb;
}

.group-header h3 {
  margin: 0;
  color: #303133;
  font-size: 16px;
}

.group-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.child-count {
  color: #909399;
  font-size: 12px;
}

.child-groups-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 20px;
}

.child-group {
  border: 1px solid #e6e8eb;
  border-radius: 6px;
  padding: 15px;
  background: #fafafa;
}

.child-group-header {
  margin-bottom: 15px;
  padding-bottom: 8px;
  border-bottom: 1px solid #dcdfe6;
}

.child-group-header h4 {
  margin: 0;
  color: #606266;
  font-size: 14px;
}

.child-parameters {
  display: grid;
  gap: 15px;
}
</style>